package com.wlyuan.open.scanner.feign.fallover;

import com.wlyuan.open.dto.OpenSearchSourceDataDTO;
import com.wlyuan.open.scanner.feign.OpenPlatformFeignInvoker;
import com.wlyuan.open.scanner.feign.exception.ErrorCode;
import com.wlyuan.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author lijing
 * @description
 */
@Component
@Slf4j
public class OpenPlatformFeignFallOverFactory implements FallbackFactory<OpenPlatformFeignInvoker> {
    @Override
    public OpenPlatformFeignInvoker create(Throwable cause) {
        logger.error("feign error : {}", cause.getMessage());
        return new OpenPlatformFeignInvoker() {

            @Override
            public Result<List<String>> fail(OpenSearchSourceDataDTO search) {
                return new Result(ErrorCode.OPEN_PLATFORM_ORDER_ERROR.getCode(), ErrorCode.OPEN_PLATFORM_ORDER_ERROR.getMessage());
            }
        };
    }
}
